﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace HelloWorldGame
{

    /// An object in the game. 
    /// It contains all the information relevant to the objects behavior and appearance.  
    public class GameThing
    {
        public Texture2D Texture;
        public Vector2 Pos;
        public Vector2 Speed;
        public float Rotation;
        public float Spin;
        public float Scale;
        public Color Tint;

        public int ScoreOnCollect;
        public int DamageOnTouch;

        public GameThing(Texture2D texture,
            Vector2 pos,
            Vector2 speed,
            int scoreOnCollect,
            int damageOnTouch,
            Color tint,
            float scale = 1f,
            float rotation = 0f,
            float spin = 1f
            )
        {
            Texture = texture;
            Pos = pos;
            ScoreOnCollect = scoreOnCollect;
            DamageOnTouch = damageOnTouch;
            Speed = speed;
            Scale = scale;
            Rotation = rotation;
            Spin = spin;
            Tint = tint;

        }

        public Rectangle getRectangle()
        {
            return new Rectangle((int)Pos.X, (int)Pos.Y, (int)(Texture.Width * Scale), (int)(Texture.Height * Scale));
        }
        
        public bool IsTouching(GameThing otherThing)
        {
            //Uses rectangles and thus doesn't take rotation into account.
            return getRectangle().Intersects(otherThing.getRectangle());
        }

        public bool IsTouching(Point point)
        {
            //Uses rectangles and thus doesn't take rotation into account.
            return getRectangle().Contains(point);
        }

        public bool IsTouching(Vector2 point)
        {
            //Uses rectangles and thus doesn't take rotation into account.
            return getRectangle().Contains(new Point((int)point.X,(int)point.Y));
        }
    }

}
